#ifndef _modelo_RANSAC_H_
#define _modelo_RANSAC_H_



#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include "videoAVI.h"

#ifdef _USE_CLASSES_
class CModelo3D {
    CModelo3D();
    ~CModelo3D();

}

class CModel2D {
 public:
    CModel2D();
    ~CModel2D();
    go_ransac();

 private:
    CModelo3D * modelo3D;

    

}

#endif


struct ransac_seq {
    struct {
	int n;
	int m;
	int nseqs;
	int total_data;
    } head;
    unsigned char *seq_data;
};

typedef struct {
    struct ransac_seq * pseqs;
    int nseqs;
    int minpoints;
    int maxpoints;
} Modelo_params;


Modelo_params * InitModelo(CALIBRATION_PARAMS_t * calL, CALIBRATION_PARAMS_t *calR);
int  Modelo(CvMat *points3D, CvMat * points, CvMat * mask, 
	    CvMat *KK, CvMat * rotation, CvMat *translation, CvMat * vect);
int  ModeloEx(CvMat *points3D, CvMat * points, CvMat * maskin,
	      CvMat *KK, CvMat * rotation, CvMat *translation, CvMat * vect);

int RANSAC_posit(CvMat *points3D, CvMat * points2D, CvMat * maskin, CvMat *maskout, 
		 CvMat *KK,
		 CvMat * rotation, CvMat * translation, CvMat * vect, 
		 float * errorout);
int GetInliersError ( CvMat *points2D, CvMat * points2D2, CvMat * maskin, CvMat *maskout, 
		      float *errorout, CvMat *dist1D);

CvKalman * InitKalman(CvMat * vect, int n1, int n2);

void DibujarModelo(IplImage * image, CvMat * points, CALIBRATION_PARAMS_t * cal, 
		   CvMat * translation, CvMat * vect, CvMat * lineas, CvMat * mask_hide,
		   CvMat * mask=NULL, CvScalar color=CV_RGB(0,0,155), int pselect = -1, 
		   CvMat *offsetvect=0);
void DibujarModelo3D(IplImage * image, CvMat * points, CALIBRATION_PARAMS_t * cal, 
		     CvMat * translation, CvMat * vect, CvMat * lineas, CvMat * mask_hide,
		     CvMat * mask = NULL, CvScalar color=CV_RGB(0,0,155), int pselect = -1,
		     bool centrar = false, CvMat *offsetvect=0);

void LineasModelo(CvMat * points3D, CvMat *lines);
CvScalar CenterModel(CvMat * XYZ);
void ChangeView(CvMat * vectL, CvMat * translationL, 
		CALIBRATION_PARAMS_t * calibration_paramsR, CvMat * vectR, CvMat * translationR, 
		CvMat * rot);
int GetNotHiden(CvMat *vect, CvMat *angY, CvMat *mask_hide);

struct line_t {
    int p1, p2;
    float z1, z2;
    CvScalar color;
    int thick;
};
	


#define MIN_INLIERS 12
#define MIN_INLIERS2 8

#ifdef _MODELO_RANSAC_CPP_

#define ITERACIONES_RANSAC_4 72 
#define ITERACIONES_RANSAC_5 146
#define ITERACIONES_RANSAC_6 293
#define ITERACIONES_RANSAC_7 588
#define ITERACIONES_RANSAC_8 1177
#define ITERACIONES_RANSAC_9 1500
#define PUNTOS_RANSAC 7
#define ITERACIONES_RANSAC ITERACIONES_RANSAC_9

#define UMBRAL_DIST_UP 12.0f
#define UMBRAL_DIST_DOWN 15q.0f

#else


#endif //_MODELO_RANSAC_CPP_
#endif //_modelo_RANSAC_H_
